using Cookbook.Common;

namespace Cookbook.Services.Core.ExceptionHandling
{
    /// <summary>
    /// Implementation of <see cref="IViolationCollection"/> that will directly throw a
    /// <see cref="RuleViolationException"/> whenever a violation is added to the collection.
    /// </summary>
    internal class ThrowingViolationCollection : IViolationCollection
    {
        /// <summary>
        /// Adds the specified rule as a violation to the collection.
        /// </summary>
        public void Add(Rule violatedRule)
        {
            throw new RuleViolationException(violatedRule);
        }

        /// <summary>
        /// Adds the specified violation to the collection.
        /// </summary>
        public void Add(Violation violation)
        {
            throw new RuleViolationException(violation.ToEnumerable());
        }

        /// <summary>
        /// If the collection contains any violation, it will throw a <see cref="RuleViolationException"/>
        /// containing all those violations.
        /// </summary>
        public void ThrowIfAny()
        {
        }
    }
}